#-----------------------------------
# Name: Chris Spooner
# Project Madlibs.py
# Period: 1
# Start Date: 9/18/2013
# Last Revision Date: 9/18/2013
# Version: 1.6.0
#----------------------------
import os

swearList = ["dumb",
             "stupid",
             "retard",
             "crap",]
             
bgColor = '0'
txtColor = 'F'

def getMenuOption(maxOptions):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter a number or S or Q> ")
        option = option.upper()
        if option == 'S':
            goodOption = True
        elif option == 'Q' :
            goodOption = True
        elif option == "":
            pass
        else:
            isNum = True
            for character in option:
                if character not in "0123456789":
                    isNum = False
            if isNum:
                if int(option) <= 0:
                    isNum = False
                elif int(option) > maxOptions:
                    isNum = False
            if isNum:
                goodOption = True
            else:
                print "Please type a number!"
        if not goodOption:
            print "Invalid Choice, please try again. "
    return option

def menu():
    print "Welcome to Madlibs"
    print "Please Select an Option:"
    print " [1] Games and monsters"
    print " [2] The Cuddly Alien Bunny"
    print " [3] Attack In Space"
    print " [S] Settings"
    print " [Q] Quit"
    option = getMenuOption(3)
    return option

def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearList:
            goodWord = True
        else:
            print "Naughty user...please be polite!"
        if not goodWord:
            print "Please try again."
    return word

def getNumber(prompt, min = "", max = ""):
        num = ""
        goodNumber = False
        while not goodNumber:
            num = raw_input(prompt)
            isNum = True
            for digit in num:
                if digit not in ".0123456789":
                    isNum = False
            if isNum:
                if min != "":
                    if float(num) < min:
                        isNum = False
                if max != "":
                    if float(num) > max:
                        isNum = False
            if isNum:
                goodNumber = True
            else:
                print "Please enter a valid number"
        return num
                    
def getColor(prompt):
    colors = ["black",
              "blue",
              "green",
              "bright white",
              "light red",
              "red"]
    opt = ""
    goodColor = False
    while not goodColor:
        opt = raw_input(prompt)
        if opt.lower() in colors:
            goodColor = True
    if opt == "black":
        color = '0'
    elif opt == 'blue':
        color = '1'
    elif opt == 'green':
        color = '2'
    elif opt == 'bright white':
        color = 'F'
    elif opt == 'light red':
        color = 'C'
    elif opt == 'red':
        color = '4'
    return color
        
            
                    
def story1():
    place1 = getWord("\nEnter a place: ")
    game = getWord("Enter the name of a game: ")
    weather1 = getWord("Enter a weather: ")
    landAction = getWord("Enter Land Action: ")
    Face = getWord("Enter facial expression: ")
    Monster1 = getWord("Enter Monster or Animal: ")
    story = "It was warm day in "
    story += place1 + ". "
    story += " \nMark, bob, and Colon were playing a game of "
    story += game + ", "
    story += "\nit was "
    story += weather1 + ", "
    story += " \nAll of a sudden wind started to howl and the land "
    story += landAction + " \nAnd the lamp posts caught on fire. "
    story += " \nThe ground exploded in front of the game center and the boys looked up in: "
    story += Face + ", "
    story += " \nAs a giant "
    story += Monster1 + ", Arose from the depths of hell!"
    story += " \nThe " + Monster1 + " quickly ate all three boys and went back to hell."
    
    print story

def story2():
    name = getWord("Enter a name: ")
    age1 = getNumber("Enter a number: ", 0)
    age2 = getNumber("Enter a number lower then the last: ", 0)
    action1 = getWord("Enter an action: ")
    creature = getWord("Enter creature: ")
    story = "I have my very own cuddly alien bunny! I named it "
    story += name + ". "
    story += "\nI think "
    story += name + " is "
    story += age1 + " years old. "
    story += " \nI remember when "
    story += name + " was " + age2 + " years old. "
    story += "  When He "
    story += action1 + " A whole building! "
    story += "\nOh No the evil "
    story += creature + " Are taking " + name + " Away! "
    story += "\n*Cries*"
    
    print story

def story3():
    name1 = getWord("Enter a name of a beefy man: ")
    name2 = getWord("Enter a name of a women...: ")
    shipName = getWord("Enter the name of a space ship: ")
    ESN = getWord("Enter the name of an evil space ship!: ")
    captain = getWord("Enter the captain of " + shipName + ": ")
    badCaptain = getWord("Enter the captain of " + ESN + ": ")
    HHPG = getWord("Enter the name of a hand held pulse gun: ")
    MPG = getWord("Enter the name of a mounted pulse gun: ")
    Star = getWord("Enter name of a star: ")
    DTime = getWord("Enter a duration of time: ")
    story = '"Captain! Captain!"'
    story += '\n"What is it "' + name1
    story += '"The Starship ' + ESN + ' Is approaching at high speed!"'
    story += '\n ' + name1 + '" Ready the ' + MPG + ','
    story += '\n ' + name2 + ' "get out the ' + HHPG + '.'
    story += '\n"Prepare to be boarded! "' 
    story += '\n "Yes Captain ' + captain + '!'
    story += '\n Aboard the ' + ESN
    story += '\n "MWA HA HA HA HA"'
    story += '\n "Captain ' + badCaptain + ' We are approaching ' + shipName + '"'
    story +=  '\n "SHOOT THEM, SHOOT THEM, MWA HA HA HA"'
    story += '\n back aboard the ' + shipName + '...'
    story += '"PREPARE FOR battle!"'
    story += '*EPIC EXPLOSION*'
    story += "* manly and lady screams as the two ships battle *"
    story += '"Its over ' + badCaptain + '"'
    story += captain + 'said after ' + DTime
    story += '"ILL BE BACK"'
    story += badCaptain + 'Disapears in a cloud of nano dust.'
    story += captain + 'looks up'
    story += '"OH SH*T"'
    story += 'he says as they run into the ' + Star
    story += '---------------------------------------'
    story += '     THE END'
    story += '---------------------------------------'
    print story
    
    
    
    
    
    
    
    
def settings():
    txtColor = getColor("Enter Text Color: ")
    bgColor = getColor("Enter Backgound Color: ")
    if txtColor != bgColor:
        os.system("color " + bgColor + txtColor)
    
def run():
    choice = ""
    while choice != 'Q':
        choice = menu()
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'S':
            settings()
        elif choice == 'Q':
            print " Goodbye"

        else:
            print "Something terrible has happened...go yell at the programmer"
    
run()
        
        
        
        
        
        
        